##测试成功
from flask import Flask, request
from flask import jsonify
from flask_cors import CORS
import server

app = Flask(__name__)
cors = CORS(app, resources={r"/getMsg": {"origins": "*"}})

rows = server.connectdb()

@app.route('/getMsg',methods=['GET','POST'])
def home():
    searchinfo = str(request.args.get('searchinfo'))
    searchresult = server.accurately_search(rows, searchinfo)
    results =[]
    for result in searchresult:
        result_s={}
        result_s['no']=result[0]
        result_s['name'] = result[1]
        result_s['picture']=result[2]
        result_s['author'] = result[3]
        result_s['introduction'] = result[4]
        result_s['classification'] = result[5]
        result_s['recommend'] = result[6]
        result_s['publish'] = result[7]
        result_s['detaillink']=result[8]
        results.append(result_s)
    print(results)
    return jsonify(results)

##启动运行
if __name__ == '__main__':
    app.run()